clear all;
close all;
fname ='cubic'
fin = fopen([fname '.dat'],'rt');
line = fgetl(fin);
a = findstr(line, ' ');
ts_ms = str2num(line(a(1)+1:a(2)));
t_len = str2num(line(a(3)+1:a(4)));
n = str2num(line(a(4)+1:end))
line = fgetl(fin);


time = [];
q1 = [];
q2 = [];
q3 = [];
t1 = [];
t2 = [];
t3 = [];
i1 = [];
i2 = [];
i3 = [];

for (i=1:n)
    line = fgetl(fin);
    a = str2num(line);
    time = [time; a(1)];
    q1 = [q1; a(2)];
    q2 = [q2; a(3)];
    q3 = [q3; a(4)];
    t1 = [t1; a(5)];
    t2 = [t2; a(6)];
    t3 = [t3; a(7)];
    i1 = [i1; a(8)];
    i2 = [i2; a(9)];
    i3 = [i3; a(10)];
end;

%regulating the data output to area of interest


fclose(fin);

scnsize = get(0,'ScreenSize');
fig = figure('Position',scnsize);
    
%fig = figure;
subplot(3,1,1)
hold all;
plot (time, q1,'--');
plot (time, i1);
title('Joint Angle q_1');
xlabel('Time (s)');
ylabel('rad');
legend('Recorded q_1','Reference q_1');

subplot(3,1,2)
hold all;
plot (time, q2,'--');
plot (time, i2);
title('Joint Angle q_2');
xlabel('Time (s)');
ylabel('rad');
legend('Recorded q_2','Reference q_2');

subplot(3,1,3)
hold all;
plot (time, q3,'--');
plot (time, i3);
title('Joint Angle q_3');
xlabel('Time (s)');
ylabel('rad');
legend('Recorded q_3','Reference q_3');

scnsize = get(0,'ScreenSize');
fig1 = figure('Position',scnsize);

subplot(3,1,1)
hold all;
plot (time, t1);
title('Torque Output on Joint 1');
xlabel('Time (s)');
ylabel('N-m');

subplot(3,1,2)
hold all;
plot (time, t2);
title('Torque Output on Joint 2');
xlabel('Time (s)');
ylabel('N-m');

subplot(3,1,3)
hold all;
plot (time, t3);
title('Torque Output on Joint 3');
xlabel('Time (s)');
ylabel('N-m');

saveas(fig,[fname '_jangles.eps']);
saveas(fig1,[fname '_torques.eps']);

    